<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="">
        <input id="input1" required type="text" name="user" />
        <input type="submit" value="提交">
    </form>
</body>

<script>
    var oText = document.getElementById("input1")

    oText.addEventListener("invalid", fn, false);

    function fn() {
        console.log(this.validity)
    }
</script>
</html>